﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace VoicePhone.Controls
{
    /// <summary>
    /// KeyBoard.xaml 的交互逻辑
    /// </summary>
    public partial class KeyBoard : UserControl
    {
        PhoneReceiverButton receiverButton;
        public Action<object, RoutedEventArgs> CallOutAction;

        public KeyBoard()
        {
            InitializeComponent();
        }

        private void UniformGrid_Click(object sender, RoutedEventArgs e)
        {
            Button btn = e.Source as Button;
            int num = 0;
            if (int.TryParse(btn.Content.ToString(), out num))
            {
                if (receiverButton.CallName.Length <= 8)
                    receiverButton.CallName += num.ToString();
            }
            else if (btn.Content.ToString() == "del")
            {
                if (receiverButton.CallName.Length > 0)
                    receiverButton.CallName = receiverButton.CallName.Remove(receiverButton.CallName.Length - 1, 1);
            }
            else
                this.CallOutAction?.Invoke(this, new RoutedEventArgs(null, new FastCallButton() { CallNo1 = receiverButton.CallName }));
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            receiverButton = this.Tag as PhoneReceiverButton;
        }
    }
}
